<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	//就是http://127.0.0.1:8080/pic/
	String basePath = "http://106.53.67.228/";
%>
<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>小说网</title>
		<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/static/css/index.css"/>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/detail.css" type="text/css"/>
		<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/btn.css" type="text/css" />
		<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/static/css/iconfont.css">
        <style>
            .icon {

                width: 1em; height: 1em;

                vertical-align: -0.15em;

                fill: currentColor;

                overflow: hidden;

            }
        </style>
		<body>
			<div id="topOne">
				<div class="nav-link">
					<a class="act" href="${pageContext.request.contextPath}/index" >畅读中文网</a><%--<em>|</em>--%>
					<div class="user">
                        <font class="iconfont">
                            <c:choose>
                                <c:when test="${user ne null }">
                                    欢迎 ${user.username }
                                    <c:if test="${userVip eq 0}">&#xe72f;</c:if>
                                    <c:if test="${userVip eq 1}"> <svg class="icon" aria-hidden="true">
                                        <use xlink:href="#icon-huiyuanjulebu1"></use>
                                    </svg></c:if>
                                </c:when>
                                <c:otherwise><a href="${pageContext.request.contextPath}/loginAndRegist.jsp">登录</a></c:otherwise>
                            </c:choose>
                        </font>
                        |
                        <font class="iconfont">
                            <c:choose>
                                <c:when test="${user ne null }"><a href="<c:url value="/user/logout"/>">退出</a></c:when>
                                <c:otherwise><a href="${pageContext.request.contextPath}/loginAndRegist.jsp">注册</a></c:otherwise>
                            </c:choose>
                        </font>
					</div>
				</div>
			</div>
			<div id="Top">
				<div class="logo">
					<a href="${pageContext.request.contextPath}/index">
						<img src="${pageContext.request.contextPath}/static/images/logoA.png" width="100px" height="50px" />
					</a>
				</div>
				<div class="search">
					<form id="search" action="<c:url value="/novel/findNovel" />" method="post">
						<div id="searchTxt" class="searchTxt">

							<div class="searchMenu">

								<%--<div class="searchSelected" id="searchSelected">玄幻</div>
                                <div style="display:none;" class="searchTab" id="searchTab">--%>
								<ul>
									<select  id="sel" name="novel.typeId" style="height:39px;border:0;padding:2px;margin:0;">
										<option value="">--请选择--</option>
										<c:forEach items="${noveltypeList }" var="noveltype">
											<option  style="background-color:transparent;"  value="${noveltype.id }">
													${noveltype.typename }
											</option>
										</c:forEach>
									</select>

								</ul>

							</div>
							<input name="novel.novelname" type="text" />
							<div class="searchBtn">
								<button id="searchBtn"></button>
							</div>
						</div>
					</form>
				</div>
			</div>
			
			<input type="hidden" id="userSession" value="${user}"/>
			<div class="box_con">
				<div class="con_top">
					<a href="${pageContext.request.contextPath}/index" title="畅读中文网">畅读中文网</a> &gt;
					<c:forEach items="${noveltypeList }" var="noveltype">
						<c:choose>
							<c:when test="${noveltype.id eq novel.typeId}">
								<a href="${pageContext.request.contextPath}/novel/findNovel?novel.typeId=${novel.typeId}" title="分类：${noveltype.typename}">${noveltype.typename}
								</a>
							</c:when>
						</c:choose>
					</c:forEach>&gt;
					<a href="#" title="${novel.novelname}">${novel.novelname}</a>
				</div>
				<div id="maininfo">
					<div id="info">
						<h1>${novel.novelname}</h1>
						<p>作&nbsp;&nbsp;者：${novel.artist}</p>
						<p>
							分&nbsp;&nbsp;类：
							<c:forEach items="${noveltypeList }" var="noveltype">
								<c:choose>
									<c:when test="${noveltype.id eq novel.typeId}">
										<a href="${pageContext.request.contextPath}/novel/findNovel?novel.typeId=${noveltype.id}" title="分类：${noveltype.typename}">${noveltype.typename}
										</a>
									</c:when>
								</c:choose>
							</c:forEach>
						</p>
						<p>
							<c:if  test="${novel.isFree eq 0}">免费书籍</c:if>
							<c:if  test="${novel.isFree eq 1}">VIP书籍</c:if>
						</p>
						<p>评分：
							${novel.avgscore}
							<%--<a href="http://www.wmxiaoshuo.com/book/91227/11/"  title="作品正文卷 第十一章：突变">作品正文卷 第十一章：突变</a>--%>
						</p>
					</div>
					<div id="intro">${novel.detail}</div>
					<div id = "btn">
					<ul>
						<li><a id="readnow" href="${pageContext.request.contextPath}/novel/read/${novel.id} " class="iconfont">立即试读&#xe778;</a></li>
						<li> <a  id="download" href="<%=basePath%>${novel.texturl}" download="abc" class="iconfont" onclick="return isVip()">开始下载&#xe618;</a>
						 	<c:if test="${novel.isFree==1}">
							（未登录用户或非会员用户只能阅读第一章）
							</c:if>
							<c:if test="${novel.isFree==0}">
								（未登录用户只能阅读第一章）
							</c:if>
						</li>
					</ul>
				</div>
				</div>
				<div id="sidebar">
					<div id="fmimg">
						<img alt="${novel.novelname}" src="<%=basePath%>${novel.pic}" width="120" height="150"><span class="a"></span></div>
				</div>
			</div>
			
			
			<div id="cmenu">
				<ul>
					<li><a id="comment1"href="javascript:void(0)"><span>评论</span></a></li>|<br />|
					<li><a id="catlog1" href="javascript:void(0)"><span>目录</span></a></li>
				</ul>
			</div>
			<div id="commentAndCatlog">
				<iframe  src="${pageContext.request.contextPath}/comAndScore/findcomment" width="1000px" frameborder="0" scrolling="no" id="test" onload="this.height=100"></iframe>
			</div>


			<div class="Footer">
				<div class="footer_nav">
					<a>关于畅读小说网</a>&#12288;|&#12288;
					<a>商务合作</a>&#12288;|&#12288;
					<a>友情链接</a>&#12288;|&#12288;
					<a>帮助中心</a>&#12288;|&#12288;
					<a>用户守则</a>&#12288;|&#12288;
					<a>网站地图</a>&#12288;|&#12288;
					<a>诚聘精英</a>&#12288;|&#12288;
					<a>畅读</a>
				</div>
				<p>
					<a>Copyright (C) 2018-2019 www.changdu.com All Rights Reserved </a>
					<br />--畅读权利声明。
				</p>
			</div>
		</body>
		<!--引用外部jquery文件-->
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/index.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/iconfont.js"></script>
		<script type="text/javascript">

			if(top.location != this.location){
				top.location.replace('${pageContext.request.contextPath}/novel/novelSearch?id=${novel.id}');
			}
				//会员下载
				function isVip(){
					var isFree = ${novel.isFree};
					console.log(isFree);

					var user="<%=session.getAttribute("user")%>";
					var userVip="<%=session.getAttribute("userVip")%>";
					<%--var isvip=0;--%>
					<%--isvip = ${user.isVip};--%>
					if(user=="null"||user==""){
						alert("请先登录");
						return false;
					}else {
						if(${novel.isFree}==0){
							$.ajax({
								url:"${pageContext.request.contextPath}/novel/addCounts",
								type:"post",
								/*  cache :false,
                                  jsonp: "callback",
                                  jsonpCallback:"success",*/
								dataType : 'text',
								success:function(data){
									console.log("ok");
									/*alert("请求成功!!");*/
								},
								error:function(data){
									/*alert("请求失败！！");*/
								}

							});
							return true;
						}else if(userVip==0){
							alert("此书为VIP书籍！");
							return false;
						}else{
							$.ajax({
								url:"${pageContext.request.contextPath}/novel/addCounts",
								type:"post",
								/*  cache :false,
                                  jsonp: "callback",
                                  jsonpCallback:"success",*/
								dataType : 'text',
								success:function(data){
									console.log("ok");
									/*alert("请求成功!!");*/
								},
								error:function(data){
									/*alert("请求失败！！");*/
								}
							});
							return true;
						};
					};
				};
				//评论与目录切换
				$("#catlog1").click(function(){
					$("iframe").prop("src","${pageContext.request.contextPath}/novel/novelCatlogue");
					$("#comment1 span").prop("style","color:#49A9A9");
					$("#catlog1 span").prop("style","color:cornflowerblue");
				});
				$("#comment1").click(function(){
					$("iframe").prop("src","${pageContext.request.contextPath}/comAndScore/findcomment");
					$("#catlog1 span").prop("style","color:#49A9A9");
					$("#comment1 span").prop("style","color:cornflowerblue");
				});
				
				//内容宽度变化的iframe高度自适应
				function reinitIframe(){
					var iframe = document.getElementById("test");
					try{
						var bHeight = iframe.contentWindow.document.body.scrollHeight;
						var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
						var height = Math.max(bHeight, dHeight);
						iframe.height = height;
						//console.log(height);
					}catch (ex){}
				}
				window.setInterval("reinitIframe()", 200);
		</script>

</html>